home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-03 | 9.1 KB | 286 lines | [TEXT/CWIE] |
- //========================================================================================
- //
- // File: Commands.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "AMSample.hpp"
-
- #ifndef COMMANDS_H
- #include "Commands.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment AMSample
- #endif
-
- FW_DEFINE_AUTO(CAMSampleEditCommand)
- FW_DEFINE_AUTO(CAMSampleDropCommand)
- FW_DEFINE_AUTO(CAMSampleDragCommand)
-
- //========================================================================================
- // CAMSampleEditCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CAMSampleEditCommand constructor
- //----------------------------------------------------------------------------------------
-
- CAMSampleEditCommand::CAMSampleEditCommand(Environment* ev,
- ODCommandID id,
- CAMSampleContent* itsContent,
- FW_CFrame* frame) :
- FW_CClipboardCommand(ev, id, frame, FW_kCanUndo),
- fAMSampleContent(itsContent)
- {
- switch (id)
- {
- case kODCommandCut:
- SetMenuStringsFromResource(ev, kAMSampleUndoStrings, kUndoCutTextMsg, kRedoCutTextMsg);
- break;
- case kODCommandClear:
- SetMenuStringsFromResource(ev, kAMSampleUndoStrings, kUndoClearTextMsg, kRedoClearTextMsg);
- break;
- case kODCommandPaste:
- SetMenuStringsFromResource(ev, kAMSampleUndoStrings, kUndoPasteTextMsg, kRedoPasteTextMsg);
- break;
- }
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleEditCommand destructor
- //----------------------------------------------------------------------------------------
-
- CAMSampleEditCommand::~CAMSampleEditCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleEditCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
-
- void CAMSampleEditCommand::SaveUndoState(Environment *ev)
- {
- fSavedTextData = fAMSampleContent->GetTextData();
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleEditCommand::UndoIt
- //----------------------------------------------------------------------------------------
-
- void CAMSampleEditCommand::UndoIt(Environment* ev)
- {
- FW_CClipboardCommand::UndoIt(ev); // call inherited
-
- switch (GetCommandID(ev))
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RestoreSelection(ev);
- break;
-
- case kODCommandPaste:
- this->SwapSelection(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleEditCommand::RedoIt
- //----------------------------------------------------------------------------------------
-
- void CAMSampleEditCommand::RedoIt(Environment *ev)
- {
- FW_CClipboardCommand::RedoIt(ev); // call inherited
-
- switch (GetCommandID(ev))
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RemoveSelection(ev);
- break;
-
- case kODCommandPaste:
- this->SwapSelection(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleEditCommand::RemoveSelection
- //----------------------------------------------------------------------------------------
-
- void CAMSampleEditCommand::RemoveSelection(Environment* ev)
- {
- fAMSampleContent->ClearTextData(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleEditCommand::RestoreSelection
- //----------------------------------------------------------------------------------------
-
- void CAMSampleEditCommand::RestoreSelection(Environment* ev)
- {
- fAMSampleContent->SetTextData(ev, fSavedTextData);
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleEditCommand::SwapSelection
- //----------------------------------------------------------------------------------------
-
- void CAMSampleEditCommand::SwapSelection(Environment* ev)
- {
- FW_CString255 textData = fAMSampleContent->GetTextData();
- fAMSampleContent->SetTextData(ev, fSavedTextData);
- fSavedTextData = textData;
- }
-
- //========================================================================================
- // CAMSampleDragCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CAMSampleDragCommand constructor
- //----------------------------------------------------------------------------------------
-
- CAMSampleDragCommand::CAMSampleDragCommand(Environment* ev,
- CAMSampleContent* content,
- FW_CFrame* frame) :
- FW_CDragCommand(ev, frame, FW_kCanUndo),
- fAMSampleContent(content)
- {
- SetMenuStringsFromResource(ev, kAMSampleUndoStrings, kUndoDragTextMsg, kRedoDragTextMsg);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleDragCommand destructor
- //----------------------------------------------------------------------------------------
-
- CAMSampleDragCommand::~CAMSampleDragCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleDragCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
-
- void CAMSampleDragCommand::SaveUndoState(Environment *ev)
- {
- fSavedTextData = fAMSampleContent->GetTextData();
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleDragCommand::UndoIt
- //----------------------------------------------------------------------------------------
-
- void CAMSampleDragCommand::UndoIt(Environment* ev)
- {
- fAMSampleContent->SetTextData(ev, fSavedTextData);
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleDragCommand::RedoIt
- //----------------------------------------------------------------------------------------
-
- void CAMSampleDragCommand::RedoIt(Environment* ev)
- {
- fAMSampleContent->ClearTextData(ev);
- }
-
- //========================================================================================
- // CAMSampleDropCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CAMSampleDropCommand constructor
- //----------------------------------------------------------------------------------------
-
- CAMSampleDropCommand::CAMSampleDropCommand(Environment *ev,
- CAMSampleContent* content,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint) :
- FW_CDropCommand(ev, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
- fAMSampleContent(content)
- {
- SetMenuStringsFromResource(ev, kAMSampleUndoStrings, kUndoDropTextMsg, kRedoDropTextMsg);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleDropCommand destructor
- //----------------------------------------------------------------------------------------
-
- CAMSampleDropCommand::~CAMSampleDropCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleDropCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
-
- void CAMSampleDropCommand::SaveUndoState(Environment *ev)
- {
- fSavedTextData = fAMSampleContent->GetTextData();
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleDropCommand::UndoIt
- //----------------------------------------------------------------------------------------
-
- void CAMSampleDropCommand::UndoIt(Environment* ev)
- {
- this->SwapSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleDropCommand::RedoIt
- //----------------------------------------------------------------------------------------
-
- void CAMSampleDropCommand::RedoIt(Environment* ev)
- {
- this->SwapSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CAMSampleDropCommand::SwapSelection
- //----------------------------------------------------------------------------------------
-
- void CAMSampleDropCommand::SwapSelection(Environment* ev)
- {
- FW_CString255 textData = fAMSampleContent->GetTextData();
- fAMSampleContent->SetTextData(ev, fSavedTextData);
- fSavedTextData = textData;
- }
-
-